﻿using AutoMapper;
using D.IdentityDbStore.Entities;

namespace D.IdentityDbStore.Mappers
{
    public static class ClientMappers
    {
        static ClientMappers()
        {
            Mapper = new MapperConfiguration(cfg => cfg.AddProfile<ClientMapperProfile>())
                .CreateMapper();
        }

        internal static IMapper Mapper { get; }

        /// <summary>
        /// Maps an entity to a model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static IdentityServer4.Models.Client ToModel(this Client entity)
        {
            return entity == null ? null : Mapper.Map< IdentityServer4.Models.Client >(entity);
        }

        /// <summary>
        /// Maps a model to an entity.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static Client ToEntity(this IdentityServer4.Models.Client model)
        {
            return model == null ? null : Mapper.Map<Client>(model);
        }
    }
}
